package com.moyun.search.common.utils;

import com.alibaba.fastjson.JSON;
import org.springframework.validation.FieldError;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ValidUtil {

    public final static String getErrorMessages(List<FieldError> errors){
        Map<String,String> errorMsgs = new HashMap<>(errors.size());
        for (FieldError error : errors) {
            errorMsgs.put(error.getField(), error.getDefaultMessage());
        }
        return JSON.toJSONString(errorMsgs);
    }
}
